package fr.umlv.m2.jee.pmlv.persistence.subject;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import fr.umlv.m2.jee.pmlv.persistence.cursus.SpecialtySubject;
import java.util.Set;
import javax.persistence.FetchType;


/**
 * Represents a Subject in school.
 * @author jenseric
 *
 */
@SuppressWarnings("serial")
@Entity
@Table(name="Subject")
public class Subject implements Serializable {

	/**
	 * The id of the subject.
	 */
	@Id
	@Column(name ="subject_id")
	private long id;
	
	/**
	 * The name of the name.
	 */
	@Column(name ="subject_name")
	private String name;
	
	@Column(name="subject_abreviation")
	private String abbreviation;
	
	/**
	 * The key words which represent the subject.
	 */
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable (
			name = "Subject__KeyWord",
			joinColumns= @JoinColumn(name="subject_id", referencedColumnName="subject_id"),
			inverseJoinColumns = @JoinColumn(name="keyWord_id", referencedColumnName="keyWord_id")
			)
	private Set<KeyWord> keyWords;
	
	
	/**
	 * List of {@link Comment} posted about the subject.
	 */
	@OneToMany(mappedBy="subject", cascade = CascadeType.ALL)
	private List<Comment> comments;


	
	@OneToMany(mappedBy="subject", fetch=FetchType.EAGER)
	private Set<SpecialtySubject> specialtySubject;
	
	/**
	 * List of themes associated by this subject.
	 */
	@OneToMany(mappedBy="subject", fetch=FetchType.EAGER)
	private Set<AbstractTheme> themes;
	

	/**
	 * Sets the id of the subject.
	 * @param id the short that is to be the id of the subject.
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * Returns the id of the subject
	 * @return the id of the subject 
	 */
	public long getId() {
		return id;
	}

	/**
	 * Sets the name of the subject.
	 * @param name the String that is to be
	 *        the name of the subject.
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	

	/**
	 * Returns the name of the subject.
	 * @return the name of the subject.
	 */
	public String getName() {
		return name;
	}
	
	
	public void setAbbreviation(String abbreviation) {
		this.abbreviation = abbreviation;
	}

	public String getAbbreviation() {
		return abbreviation;
	}

	/**
	 * Sets the set of key words.
	 * @param keyWords the List that is to be the set of key words
	 *        of the subject.
	 */
	public void setKeyWords(Set<KeyWord> keyWords) {
		this.keyWords = keyWords;
	}

	/**
	 * Returns the list of Key words.
	 * @return the list of key words of the subject.
	 */
	public Set<KeyWord> getKeyWords() {
		return keyWords;
	}

	/**
	 * Sets the list of comments about the subject.
	 * @param comments the List that is to be the set of comments
	 *        about the subject
	 */
	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

	/**
	 * Returns a list of comments posted about the subject.
	 * @return a list of comments posted about the subject.
	 */
	public List<Comment> getComments() {
		return comments;
	}


	/**
	 * Sets the List of themes associated by this subject.
	 * @param themes the set of {@link Theme} that is to be associated by
	 *        the subject.
	 */
	public void setThemes(Set<AbstractTheme> themes) {
		this.themes = themes;
	}

	/**
	 * Returns the list of themes associated by this subject.
	 * @return the list of {@link Theme} associated by this subject.
	 */
	public Set<AbstractTheme> getThemes() {
		return themes;
	}

	public void setSpecialtySubject(Set<SpecialtySubject> specialtySubject) {
		this.specialtySubject = specialtySubject;
	}

	public Set<SpecialtySubject> getSpecialtySubject() {
		return specialtySubject;
	}


	
	
	
}
